package com.zyx.nettypro.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @author zyx
 * @since 2021/9/19 15:23
 * desc:
 */
public class FileChannelCopy {
    public static void main(String[] args) throws IOException {
        // 创建相关流
        FileInputStream fileInputStream = new FileInputStream("input/netty/01.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("input/netty/a2.jpg");

        // 获取各个流对应的filechannel
        FileChannel sourceCh = fileInputStream.getChannel();
        FileChannel destCh = fileOutputStream.getChannel();

        // 使用transferForm完成拷贝
        destCh.transferFrom(sourceCh, 0, sourceCh.size());
        // 关闭相关通道和流
        sourceCh.close();
        destCh.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
